<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>充值审核</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript" src="${ctxStatic}/common/base-loading.js"></script>
	<script type="text/javascript">
	$(document).ready(function() {
		setTimeout(GetDate, 1000);
		var container = $('div.container');
		//表单验证
		$("#rechargeForm").validate({
			submitHandler: function(form){
				loading('正在提交，请稍等...');
				form.submit();
			},
		});
		$("#checkAll").click(function () {
			$("input[name='id']:checkbox").prop("checked", this.checked);            
		});
	});
	function GetDate(){
		$("#contentTable tbody").find("tr").each(function () {
		 var name = "";
         var numbers = $(this).find("td:eq(2)");//卡号
         var iccid = $(this).find("td:eq(1)").html();//iccid
         console.log(iccid)
         //查询卡状态
          $.ajax({
            type: "get",
            async: true,
            url: "${ctx}/orders/rechargeOrder/getNumberByIccid?iccid=" + iccid,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function (data, textStatus) {
            	numbers.html(data);
            		}
        		}); 

    		})
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		//审核操作
		var id = '';
		function examineBtn(ids){
			$("#id").val(ids)
			id = ids;
			$.jBox.confirm("您确定审核操作吗？", "提示信息", submit, { buttons: { '通过': true, '不通过': false} });
		}
		var submit = function (v, h, f) {
		    if (v == true)
		    	$('#myModal').modal("show");//打开模态框
		    else
				//审核不通过
				window.location.href = "${ctx}/orders/rechargeOrder/examine?id="+id+"&rechargeState="+3;
		    return true;
		};
		
		
		//批量审核
		function examineBtn(){
			var list = [];
			$("#contentTable .checkbox-hook:checked").each(function (){
				list.push($(this).val());
			})
			if(list.length == 0){
				$.jBox.tip('请至少选择一条数据审核。', 'error');
			}else{
				console.log(list)
				$.jBox.confirm("确认要审核通过"+list.length+"条订单信息吗？", "提示信息", examineSubmit, { buttons: { '确定': true, '取消': false} });
				$("#ids").val(list);
			}
		}
		var examineSubmit = function (v, h, f) {
		    if (v == true){
		    	loading('数据处理中，请稍等...');
	    		$("#examineForm").attr("action", "${ctx}/orders/rechargeOrder/batchExamine");
	    		$("#examineForm").submit();
		    }
		    return true;
		};
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/orders/rechargeOrder/examineList">充值审核列表</a></li>
	</ul>
	<!-- 审核div -->
	<form id="rechargeForm"  action="${ctx}/orders/rechargeOrder/examine" method="post" class="form-horizontal">
		<div id="myModal" style="width:400px;" class="modal hide fade" tabindex="-1" role="dialog"  aria-hidden="false">
		  <div class="modal-header">
		    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		    <h3 id="myModalLabel">充值订单审核</h3>
		  </div>
		  	<input id="id" name="id" type="hidden" value="">
		  	<input id="rechargeState" name="rechargeState" type="hidden" value="2">
			<div class="controls" style="margin-left: 5px;margin-top:10px;margin-bottom: 10px;">
				充值订单号:<input style="width:180px;" name="rechargeOrderNo" id="rechargeOrderNo" digits="true" htmlEscape="false"  maxlength="20" minlength="1" class="input-xlarge required"/>
			</div>
		  <div class="modal-footer">
		    <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>&nbsp;
		    <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
		  </div>
		</div>
	</form>
	<form:form id="searchForm" modelAttribute="rechargeOrder" action="${ctx}/orders/rechargeOrder/examineList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>ICCID：</label>
				<form:input path="iccid" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li style="margin-left:20px;"><label>套 餐 类 型：</label>
				<form:select path="pkgType" class="input-medium" style="width:177px;">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('pkg')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li style="margin-left:20px;"><label>充值状态：</label>
				<form:select path="rechargeState" class="input-medium" style="width:177px;">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('rechargeState')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>订单号：</label>
				<form:input path="orderNo" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li><label>充值订单号：</label>
				<form:input path="rechargeOrderNo" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li class="btns">
				<a id="btnSubmit" class="btn btn-primary" onclick="return page();"><i class="icon-search"></i>&nbsp;查询</a>
			</li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<div class="breadcrumb">
		<shiro:hasPermission name="orders:examine:examine">
			<form id="examineForm" method="post" style="display:inline-block;margin: 0 0 0px">
				<input type="hidden" id="ids" name="ids" value=""/>
		  		<a  type="button" onclick="examineBtn()" class="btn btn-primary" ><i class="icon-pencil"></i>&nbsp;批量审核</a>
		  	</form>
	  	</shiro:hasPermission>
	 </div>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th><input type="checkbox" id="checkAll"/></th>
				<th>iccid</th>
				<th>卡号</th>
				<th>订单号</th>
				<th>充值订单号</th>
				<th>所属代理商</th>
				<th>所属套餐类型</th>
				<th>套餐</th>
				<th>充值金额</th>
				<th>支付状态 </th>
				<th>充值状态</th>
				<th>创建时间</th>
				<th>支付时间</th>
				<th>充值时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:choose>
			<c:when test="${not empty page.list}">
				<c:forEach items="${page.list}" var="rechargeOrder">
					<tr>
						<td><input class="checkbox-hook" type="checkbox" name="id" value="${rechargeOrder.id}"/></td>
						<td>
							${rechargeOrder.iccid}
						</td>
						<td>
							<span >加载中...</span>
						</td>
						<td>
							${rechargeOrder.orderNo}
						</td>
						<td>
							${rechargeOrder.rechargeOrderNo}
						</td>
						<td>
							${rechargeOrder.officeName}
						</td>
						<td>
							${fns:getDictLabel(rechargeOrder.pkgType, 'pkg', '未知')}
						</td>
						<td>
							${rechargeOrder.pkg}
						</td>
						<td>
							${rechargeOrder.money}
						</td>
						<td>
							${fns:getDictLabel(rechargeOrder.payState, 'payState', '未知')}
						</td>
						<td>
							${fns:getDictLabel(rechargeOrder.rechargeState, 'rechargeState', '未知')}
						</td>
						<td>
							<fmt:formatDate value="${rechargeOrder.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
							<fmt:formatDate value="${rechargeOrder.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
							<fmt:formatDate value="${rechargeOrder.rechargeTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
							<shiro:hasPermission name="orders:examine:examine">
							<a title="审核" onclick="examineBtn('${rechargeOrder.id}')" href="#" class="btn-link"><i class="icon-pencil"></i></a>&nbsp;</a>
							</shiro:hasPermission> 
						</td>
					</tr>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<tr>
					<td colspan="13" style="text-align: center;font-size:17px; font-family:SimHei">未查询到数据...</td>
				</tr>
			</c:otherwise>
			</c:choose>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>